define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pay/pay/index'+location.search,
                    del_url: 'pay/pay/del',
                    supplementary_url: 'pay/pay/supplementary',
                    table: 'pay',
                },
                pageSize: 5, //调整分页大小为20
                pageList:[5,10,20,30]
            });
          

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                // 当访问列表发起ajax请求数据
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                // 主键
                pk: 'id',
                // 设置默认排序
                sortName: 'createtime',
                sortOrder: 'desc',
                search: false, // 取消快速搜索框
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        { field: 'id', title: __('Id'), sortable: true },
                        { field: 'code', title: __('Code')},
                        { field: 'name', title: __('Name'), operate: 'LIKE' },
                        { field: 'third', title: __('Third'),searchable:false },
                        { field: 'paytype', title: __('Paytype'),searchList: {"0":__('微信支付'),"1":__('支付宝支付')}, formatter: Table.api.formatter.normal },
                        { field: 'originalprice', title: __('Originalprice') },
                        { field: 'price', title: __('Price') },
                        { field: 'status', title: __('Status'), searchList: {"0":__('待支付'),"1":__('已支付'),"2":__('已关闭')},formatter: Table.api.formatter.status},
                        { field: 'createtime', title: __('Ceatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        { field: 'paytime_text', title: __('Paytime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime  },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                        buttons: [
                            {
                                name: '支付补单',
                                title: __('补单'),
                                classname: 'btn btn-success btn-xs btn-ajax',
                                icon: 'fa fa-reply',
                                url: 'pay/pay/supplementary',
                                extend: 'data-toggle="tooltip" data-container="body"',
                                confirm: '确定补单吗',
                                refresh: true, //操作完成后是否刷新列表
                            }] }
                    ]
                ]
            })
            $(".pay").click(function () {
                $ids = Table.api.selectedids(table)
                layer.confirm('确定补单' + $ids.length + "条数据吗?", { icon: 3, title: '提示' }, function (index) {
                    if (index) {
                        Backend.api.ajax("pay/pay/supplementary?ids=" + $ids.join(","), function (response) {
                            // 处理返回的结果
                            layer.close(index);
                            // 刷新数据表格
                            table.bootstrapTable('refresh')
                        })

                    }
                    layer.close(index);
                });
            }),
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        del: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    }

    return Controller;
});
